package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.ProInfo;
import com.whnk.pm.service.IProInfoService;

/**
 * 项目基本 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-24
 */
@Controller
@RequestMapping("/pm/proInfo")
public class ProInfoController extends BaseController
{
    private String prefix = "pm/proInfo";
	
	@Autowired
	private IProInfoService proInfoService;
	
	@RequiresPermissions("pm:proInfo:view")
	@GetMapping()
	public String proInfo()
	{
	    return prefix + "/proInfo";
	}
	
	/**
	 * 查询项目基本列表
	 */
	@RequiresPermissions("pm:proInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProInfo proInfo)
	{
		startPage();
        List<ProInfo> list = proInfoService.selectProInfoList(proInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增项目基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存项目基本
	 */
	@RequiresPermissions("pm:proInfo:add")
	@Log(title = "项目基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProInfo proInfo)
	{		
		return toAjax(proInfoService.insertProInfo(proInfo));
	}

	/**
	 * 修改项目基本
	 */
	@GetMapping("/edit/{proId}")
	public String edit(@PathVariable("proId") Integer proId, ModelMap mmap)
	{
		ProInfo proInfo = proInfoService.selectProInfoById(proId);
		mmap.put("proInfo", proInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存项目基本
	 */
	@RequiresPermissions("pm:proInfo:edit")
	@Log(title = "项目基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProInfo proInfo)
	{		
		return toAjax(proInfoService.updateProInfo(proInfo));
	}
	
	/**
	 * 删除项目基本
	 */
	@RequiresPermissions("pm:proInfo:remove")
	@Log(title = "项目基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(proInfoService.deleteProInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param proId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:proInfo:detail")
    @GetMapping("/detail/{proId}")
    public String detail(@PathVariable("proId") Integer proId, ModelMap mmap)
    {
		ProInfo proInfo = proInfoService.selectProInfoById(proId);
		mmap.put("proInfo", proInfo);
        return prefix + "/detail";
    }
	
	/**
	 * 更新项目成员信息
	 * 
	 * @param proId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/upEmpForPro/{proId}")
    public String upEmpForPro(@PathVariable("proId") Integer proId, ModelMap mmap)
    {
		ProInfo proInfo = proInfoService.selectProInfoById(proId);
		mmap.put("proInfo", proInfo);
        return "pm/proMem/proMem";
    }
	
}
